home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / Developer Essentials Jul 90 / Apple II / Programming & Utilities / Apple IIgs APW Intro Prog Src / HP.PAS / MENU.PAS.txt < prev    next >
Encoding:
Text File  |  1987-09-13  |  5.6 KB  |  187 lines

  1. UNIT Menu;
  2.  
  3. {+----------------------------------------------------------------------------+
  4.  |                                                                            |
  5.  |         HodgePodge:  An example Apple IIGS Desktop application             |
  6.  |                                                                            |
  7.  |    Written in 65816 assembler and APW C by the Apple IIGS Tools Team       |
  8.  |              Translated to TML Pascal by TML Systems, Inc.                 |
  9.  |  Modified by Ben Koning for "Programmer's Introduction to the Apple IIGS"  |
  10.  |                                                                            |
  11.  |             Copyright (c) 1986-87 by Apple Computer, Inc.                  |
  12.  |                Copyright (c) 1987 by TML Systems, Inc.                     |
  13.  |                                                                            |
  14.  |                     --------------------------------                       |
  15.  |                                                                            |
  16.  |     Pascal UNIT "MENU.PAS" : Menu bar setup and menu item handling         |
  17.  |                                                                            |
  18.  +----------------------------------------------------------------------------+}
  19.  
  20.  
  21.  
  22. INTERFACE
  23.  
  24. USES
  25.        HPIntfData,         {HodgePodge Apple IIGS Toolbox Interface Units}
  26.        HPIntfProc,
  27.        HPIntfPdos,
  28.  
  29.        Globals,            {HodgePodge Code Units}
  30.        Dialog,
  31.        Font,
  32.        Paint,
  33.        Window,
  34.        Print;
  35.  
  36.  
  37.  
  38. procedure DoMenu;      {Execute a menu item}
  39. procedure SetUpMenus;  {Install menus and redraw menu bar}
  40.  
  41.  
  42.  
  43.  
  44.  
  45. IMPLEMENTATION
  46.  
  47.  
  48.  
  49. procedure AddToMenu;
  50.  
  51.    {Private routine to add a new window item to the "Windows" menu after a
  52.     new window has been drawn.  Increments the variable WIndex, a count of
  53.     the number of windows currently open.}
  54.  
  55.    var theWindow    : GrafPortPtr;
  56.        myDataHandle : WindDataH;
  57.  
  58.    begin   {of AddToMenu}
  59.        theWindow           := FrontWindow;
  60.        WindowList [WIndex] := theWindow;
  61.  
  62.        myDataHandle := WindDataH (GetWRefCon (theWindow));
  63.  
  64.        InsertMItem (@myDataHandle^^.menuStr [1],$FFFF,WindowsMenuID);
  65.  
  66.        if WIndex = 0 then begin                {This is the first window}
  67.            DeleteMItem (NoWindowsItem);        {Remove the "filler" item}
  68.            SetMenuFlag ($FF7F,WindowsMenuID);  {Highlight the menu}
  69.            DrawMenuBar;
  70.        end;
  71.  
  72.        CalcMenuSize (0,0,WindowsMenuID);
  73.        Inc (WIndex);
  74.    end;    {of AddToMenu}
  75.  
  76.  
  77.  
  78. procedure DoOpenItem;
  79.  
  80.    {Private routine which is called when the "Open..." item from the "File"
  81.     menu OR the "Display Font..." item from the "Fonts" menu is selected
  82.     (OpenWindow will determine which one it was).  If too many windows are
  83.     already open, then a dialog is displayed.}
  84.  
  85.    begin   {of DoOpenItem}
  86.        if WIndex < LastWind then
  87.            if OpenWindow then
  88.                AddtoMenu
  89.            else
  90.        else
  91.            ManyWindDialog;
  92.    end;    {of DoOpenItem}
  93.  
  94.  
  95.  
  96. procedure DoQuitItem;
  97.  
  98.    {Private routine to set Done flag if the "Quit" item was selected}
  99.  
  100.    begin   {of DoQuitItem}
  101.        Done := true;
  102.    end;    {of DoQuitItem}
  103.  
  104.  
  105.  
  106. procedure DoWindow (itemNum: integer);
  107.  
  108.    {Private routine which brings a specific window to the front of the
  109.     desktop, in response to a selection from the "Windows" menu.}
  110.  
  111.    var theWindow: GrafPortPtr;
  112.  
  113.    begin   {of DoWindow}
  114.        theWindow := WindowList [itemNum - FirstWindItem];
  115.        SelectWindow (theWindow);
  116.        ShowWindow   (theWindow);
  117.    end;    {of DoWindow}
  118.  
  119.  
  120.  
  121. procedure DoMenu;
  122.  
  123.    {Procedure to handle all menu selections.  Examines the Event.TaskData
  124.     menu item ID word from TaskMaster (from Event Manager) and calls the
  125.     appropriate routine.  While the routine is running the menu title is
  126.     still highlighted.  After the routine returns, we unhilight the
  127.     menu title.}
  128.  
  129.    var menuNum : integer;
  130.        itemNum : integer;
  131.  
  132.    begin   {of DoMenu}
  133.  
  134.        menuNum := HiWord (Event.wmTaskData);
  135.        itemNum := LoWord (Event.wmTaskData);
  136.    
  137.        case itemNum of
  138.            AboutItem    :  DoAboutItem;
  139.            OpenItem     :  DoOpenItem;
  140.            CloseItem    :  DoCloseItem;
  141.            SaveAsItem   :  DoSaveItem;
  142.            ChoosePItem  :  DoChooserItem;
  143.            PageSetItem  :  DoSetupItem;
  144.            PrintItem    :  DoPrintItem;
  145.            QuitItem     :  DoQuitItem;
  146.            UndoItem     :  ;
  147.            CutItem      :  ;
  148.            CopyItem     :  ;
  149.            PasteItem    :  ;
  150.            ClearItem    :  ;
  151.            FontItem     :  DoOpenItem;
  152.            MonoItem     :  DoSetMono;
  153.        otherwise
  154.            DoWindow (itemNum);
  155.        end;
  156.  
  157.        HiliteMenu (false,menuNum);     {Unhighlight the menu title}
  158.  
  159.    end;    {of DoMenu}
  160.  
  161.  
  162.  
  163. procedure SetUpMenus;
  164.  
  165.    {Procedure to install our menu titles and their items in the system menu
  166.     bar and to redraw it so we can see them.}
  167.  
  168.    var Height : integer;
  169.  
  170.    begin   {of SetUpMenus}
  171.        SetMTitleStart(10);                       {Set Starting position of menu}
  172.  
  173.        InsertMenu (NewMenu (@FontMenuStr   [1]),0);    {Fonts Menu  }
  174.        InsertMenu (NewMenu (@WindowMenuStr [1]),0);    {Window Menu }
  175.        InsertMenu (NewMenu (@EditMenuStr   [1]),0);    {Edit Menu   }
  176.        InsertMenu (NewMenu (@FileMenuStr   [1]),0);    {File Menu   }
  177.        InsertMenu (NewMenu (@AppleMenuStr  [1]),0);    {Apple Menu  }
  178.  
  179.        FixAppleMenu (AppleMenuID);               {Add DAs to apple menu    }
  180.        Height := FixMenuBar;                     {Set sizes of menus       }
  181.        DrawMenuBar;                              {...and draw the menu bar!}
  182.    end;    {of SetUpMenus}
  183.  
  184.  
  185.  
  186. END.
  187.